<template>
  <div class="app-container">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="基础设置" name="baseConfig">
        <el-container>
          <!--          <el-form :model="form" label-width="80px">
                      <el-form-item label="活动名称">
                        <el-input v-model="form.name"></el-input>
                      </el-form-item>
                      <el-form-item label="活动区域">
                        <el-select v-model="form.region" placeholder="请选择活动区域">
                          <el-option label="区域一" value="shanghai"></el-option>
                          <el-option label="区域二" value="beijing"></el-option>
                        </el-select>
                      </el-form-item>
                      <el-form-item label="活动时间">
                        <el-col :span="11">
                          <el-date-picker type="date" placeholder="选择日期" v-model="form.date1" style="width: 100%;"></el-date-picker>
                        </el-col>
                        <el-col class="line" :span="2">-</el-col>
                        <el-col :span="11">
                          <el-time-picker placeholder="选择时间" v-model="form.date2" style="width: 100%;"></el-time-picker>
                        </el-col>
                      </el-form-item>
                      <el-form-item label="即时配送">
                        <el-switch v-model="form.delivery"></el-switch>
                      </el-form-item>
                      <el-form-item label="活动性质">
                        <el-checkbox-group v-model="form.type">
                          <el-checkbox label="美食/餐厅线上活动" name="type"></el-checkbox>
                          <el-checkbox label="地推活动" name="type"></el-checkbox>
                          <el-checkbox label="线下主题活动" name="type"></el-checkbox>
                          <el-checkbox label="单纯品牌曝光" name="type"></el-checkbox>
                        </el-checkbox-group>
                      </el-form-item>
                      <el-form-item label="特殊资源">
                        <el-radio-group v-model="form.resource">
                          <el-radio label="线上品牌商赞助"></el-radio>
                          <el-radio label="线下场地免费"></el-radio>
                        </el-radio-group>
                      </el-form-item>
                      <el-form-item label="活动形式">
                        <el-input type="textarea" v-model="form.desc"></el-input>
                      </el-form-item>
                      <el-form-item>
                        <el-button type="primary" @click="onSubmit">立即创建</el-button>
                        <el-button>取消</el-button>
                      </el-form-item>
                    </el-form>-->
        </el-container>
      </el-tab-pane>
      <el-tab-pane label="商家信息" name="shopConfig">
        <el-container>
          <el-form :model="form" ref="shopConfig" label-width="120px">
            <el-form-item label="配送方式" prop="sendType">
              <el-radio-group v-model="form.sendType">
                <el-radio :label="'1'">店内就餐</el-radio>
                <el-radio :label="'2'">外卖送餐</el-radio>
                <el-radio :label="'3'">店内就餐+外卖送餐</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="商家店名" prop="shopName">
              <el-input v-model="form.shopName"></el-input>
            </el-form-item>
            <el-form-item label="商家店铺地址" prop="address">
              <el-input v-model="form.address"></el-input>
            </el-form-item>
            <el-form-item label="商家电话" prop="tel">
              <el-input v-model="form.tel"></el-input>
            </el-form-item>
            <el-form-item label="配送时间" prop="startSendTime">
              <el-col :span="11">
                <el-time-picker value-format="HH:mm:ss" placeholder="开始时间" v-model="form.startSendTime"
                                style="width: 100%;"></el-time-picker>
              </el-col>
              <el-col class="line" :span="2">-</el-col>
              <el-col :span="11">
                <el-time-picker value-format="HH:mm:ss" placeholder="结束时间" v-model="form.endSendTime"
                                style="width: 100%;"></el-time-picker>
              </el-col>
            </el-form-item>
            <el-form-item label="配送费">
              <el-input v-model="form.sendMoney"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="onSubmit('shopConfig')">提交修改</el-button>
            </el-form-item>
          </el-form>
        </el-container>
      </el-tab-pane>
      <el-tab-pane label="微信" name="WxConfig">
        <el-form :model="form" ref="WxConfig" label-width="120px">
          <el-form-item label="小程序AppID">
            <el-input style="width:40%" v-model="form.miniAppId"></el-input>
          </el-form-item>
          <el-form-item label="小程序秘钥">
            <el-input style="width:40%" v-model="form.miniAppSecret"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit('WxConfig')">提交修改</el-button>
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="打印机" name="touchConfig"></el-tab-pane>
      <el-tab-pane label="短信接口" name="messageConfig"></el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
import {getSysConfig, updateConfig} from "@/api/shop/sysConfig";
import Vue from "vue";
import * as categoryApi from "@/api/shop/category";

export default {
  name: 'ShopConfig',
  data() {
    return {
      activeName: 'shopConfig',
      form: {
        miniAppId: "这个功能没有实现，配置appid和秘钥到系统管理-参数设置配置",
        miniAppSecret: '这个功能没有实现，配置appid和秘钥到系统管理-参数设置配置'
      }
    }
  },
  mounted() {
    this.init(this.activeName);
  },
  methods: {
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          updateConfig({
            ...this.form
          }).then((res) => {
            this.msgSuccess("修改成功");
          })
        } else {
          return false;
        }
      });
    },
    handleClick(tab) {
      this.init(tab.name);
    },
    init(tabName) {
      let that = this;
      getSysConfig(tabName).then((res) => {
        res.data.forEach((item) => {
          Vue.set(that.form, item.keyStr, item.valueStr);
          that.form.miniAppId = "这个功能没有实现，配置appid和秘钥到系统管理-参数设置配置"
          that.form.miniAppSecret = "这个功能没有实现，配置appid和秘钥到系统管理-参数设置配置"
        });
      });
    }
  }
};
</script>
<style scoped>

</style>
